package com.pakazaka.roguelike.ui;

import com.pakazaka.player.Equip;
import com.pakazaka.player.Player;
import com.pakazaka.roguelike.body.BodyPart;
import com.pakazaka.testItemsSystem.Item;
import java.awt.Color;
import java.awt.Graphics;

/**
 *
 * @author Remi
 */
public class MainInfo {
    private static final Color green = new Color(0, 125, 0),
            yellow = new Color(155, 155, 0),
            red = new Color(155, 0, 0),
            blue = new Color(60, 60, 205);
    private static final int EQUIP_LIST_X_OFFSET = 462;
    private static final int EQUIP_STATES_X_OFFSET = 612;
    private static final String[] slots = {"glasses", "mask", "helmet", "t-shirt", "jacket",
        "cloak", "legs", "boots", "left hand", "right hand", "backpack"};

    public static void paint(Graphics g, Player hero) {
        g.drawString(hero.getNick() + " the Survivor", 312, 16);

        //отрисовка полоски здоровья
        switchColor(g, hero.getBodyPart(BodyPart.BP_HEAD).getHP(), hero.getBodyPart(BodyPart.BP_HEAD).getMaxHP());
        //head
        g.fillRect(312, 150, (100 * hero.getBodyPart(BodyPart.BP_HEAD).getHP()) / hero.getBodyPart(BodyPart.BP_HEAD).getMaxHP(), 12);
        //torso
        switchColor(g, hero.getBodyPart(BodyPart.BP_TORSO).getHP(), hero.getBodyPart(BodyPart.BP_TORSO).getMaxHP());
        g.fillRect(312, 170, (100 * hero.getBodyPart(BodyPart.BP_TORSO).getHP()) / hero.getBodyPart(BodyPart.BP_TORSO).getMaxHP(), 12);
        //hands
        switchColor(g, hero.getBodyPart(BodyPart.BP_HANDS).getHP(), hero.getBodyPart(BodyPart.BP_HANDS).getMaxHP());
        g.fillRect(312, 190, (100 * hero.getBodyPart(BodyPart.BP_HANDS).getHP()) / hero.getBodyPart(BodyPart.BP_HANDS).getMaxHP(), 12);
        //legs
        switchColor(g, hero.getBodyPart(BodyPart.BP_LEGS).getHP(), hero.getBodyPart(BodyPart.BP_LEGS).getMaxHP());
        g.fillRect(312, 210, (100 * hero.getBodyPart(BodyPart.BP_LEGS).getHP()) / hero.getBodyPart(BodyPart.BP_LEGS).getMaxHP(), 12);

        g.setColor(Color.white);
        g.drawString("HEAD", 312, 160);
        g.drawString("TORSO", 312, 180);
        g.drawString("HANDS", 312, 200);
        g.drawString("LEGS", 312, 220);

        g.drawString("thirst: " + hero.getDebuffState(Player.EffectType.THIRST), EQUIP_STATES_X_OFFSET, 220);
        g.drawString("drunkenness: " + hero.getDebuffState(Player.EffectType.DRUNKENNESS), EQUIP_STATES_X_OFFSET, 200);
        g.drawString("hunger: " + hero.getDebuffState(Player.EffectType.HUNGER), EQUIP_STATES_X_OFFSET, 180);

        if (hero.getEquip().getEquippedItem(Equip.SLOT_BACKPACK) != null) {
            g.drawString("backpack: " + hero.getEquip().getEquippedItem(Equip.SLOT_BACKPACK).getName(), 712, 220);
        } else {
            //g.drawString("backpack: none", 712, 220);
        }

        if (hero.getEquip().getEquippedItem(Equip.SLOT_BOOTS) != null) {
            Item boots = hero.getEquip().getEquippedItem(Equip.SLOT_BOOTS);
            g.drawString("boots: " + boots.getName(), 712, 200);
        } else {
            //g.drawString("boots: none", 712, 200);
        }

        for (int i = 0; i < slots.length; i++) {
            final Item equippedItem = hero.getEquip().getEquippedItem(i);
            if (equippedItem != null) {
                g.drawString(slots[i] + ": " + equippedItem.getName(), EQUIP_LIST_X_OFFSET, 20 * i + 20);
            } else {
                g.drawString(slots[i] + ": " + "none", EQUIP_LIST_X_OFFSET, 20 * i + 20);
            }
        }

        g.setColor(red);
        g.drawString("STR: " + hero.getBaseStrength() + " (-" + hero.getStrengthPenalty() + ")", 312, 40);
        g.setColor(green);
        g.drawString("DEX: " + hero.getBaseDexterity(), 312, 60);
        g.setColor(Color.WHITE);
        g.drawString("STA: " + hero.getBaseStamina(), 312, 80);
        g.setColor(blue);
        g.drawString("INT: " + hero.getBaseIntelligence(), 312, 100);
        g.setColor(Color.LIGHT_GRAY);
        g.drawString("DEFENCE: " + hero.getEquip().getProtectionValue(), 312, 120);
    }

    private static void switchColor(Graphics g, int hp, int max_hp) {
        if (hp >= max_hp / 3 * 2) {
            g.setColor(green);
        }
        if ((hp > max_hp / 3) && (hp < max_hp / 3 * 2)) {
            g.setColor(yellow);
        }
        if (hp <= max_hp / 3) {
            g.setColor(red);
        }
    }
}
